home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS / h / ASTBase.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-14  |  3.2 KB  |  103 lines  |  [TEXT/MPS ]

  1. /* Abstract syntax tree
  2.  *
  3.  * SOFTWARE RIGHTS
  4.  *
  5.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  6.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  7.  * company may do whatever they wish with source code distributed with
  8.  * PCCTS or the code generated by PCCTS, including the incorporation of
  9.  * PCCTS, or its output, into commerical software.
  10.  * 
  11.  * We encourage users to develop software with PCCTS.  However, we do ask
  12.  * that credit is given to us for developing PCCTS.  By "credit",
  13.  * we mean that if you incorporate our source code into one of your
  14.  * programs (commercial product, research project, or otherwise) that you
  15.  * acknowledge this fact somewhere in the documentation, research report,
  16.  * etc...  If you like PCCTS and have developed a nice tool with the
  17.  * output, please mention that you developed it using PCCTS.  In
  18.  * addition, we ask that this header remain intact in our source code.
  19.  * As long as these guidelines are kept, we expect to continue enhancing
  20.  * this system and expect to make other tools available as they are
  21.  * completed.
  22.  *
  23.  * ANTLR 1.23
  24.  * Terence Parr
  25.  * Parr Research Corporation
  26.  * with Purdue University and AHPCRC, University of Minnesota
  27.  * 1989-1994
  28.  */
  29.  
  30. #ifndef ASTBase_H
  31. #define ASTBase_H
  32.  
  33. #include <stdio.h>
  34.  
  35. /*
  36.  * Notes:
  37.  *
  38.  * To specify a copy constructor, subclass one of these classes and
  39.  * give the copy constructor.  For dup(), you must override the inheritance
  40.  * also as this is copying tree nodes.
  41.  */
  42.  
  43. class ASTBase {
  44. protected:
  45.     ASTBase *_right, *_down;
  46.  
  47. public:
  48.     ASTBase() { _right = _down = NULL; }
  49.     virtual ~ASTBase() { ; }
  50.     ASTBase *right() { return _right; }
  51.     ASTBase *down() { return _down; }
  52.     void setRight(ASTBase *r) { _right = r; }
  53.     void setDown(ASTBase *d) { _down = d; }
  54.     ASTBase *dup();
  55.     void destroy();
  56.     void preorder();
  57.     static ASTBase *tmake(ASTBase *, ...);
  58.     static void link(ASTBase **, ASTBase **, ASTBase **);
  59.     void subchild(ASTBase **, ASTBase **, ASTBase **);
  60.     void subroot(ASTBase **, ASTBase **, ASTBase **);
  61.     virtual void preorder_action() { ; }
  62.     virtual void preorder_before_action() { printf(" ("); }
  63.     virtual void preorder_after_action() { printf(" )"); }
  64. };
  65.  
  66. #ifdef NOT_DONE
  67. class ASTSorcererCompatibleBase : public ASTBase {
  68. protected:
  69.     ASTBase *_right[2], *_down[2];
  70.  
  71. public:
  72.     ASTBase() { _right = _down = NULL; }
  73.     virtual ~ASTBase() { ; }
  74.     ASTBase *right() { return _right; }
  75.     ASTBase *down() { return _down; }
  76.     setRight(ASTBase *r) { _right = r; }
  77.     setDown(ASTBase *d) { _down = d; }
  78.     ASTBase *dup();
  79.     void destroy();
  80.     void preorder();
  81.     static ASTBase *tmake(ASTBase *, ...);
  82.     static void link(ASTBase **, ASTBase **, ASTBase **);
  83.     void subchild(ASTBase **, ASTBase **, ASTBase **);
  84.     void subroot(ASTBase **, ASTBase **, ASTBase **);
  85.     virtual void preorder_action() { ; }
  86.     virtual void preorder_before_action() { printf(" ("); }
  87.     virtual void preorder_after_action() { printf(" )"); }
  88. };
  89. #endif
  90.  
  91. class ASTDoublyLinkedBase : public ASTBase {
  92. protected:
  93.     ASTDoublyLinkedBase *_left, *_up;
  94. public:
  95.     void double_link(ASTBase *left, ASTBase *up);
  96.     ASTDoublyLinkedBase *dup();
  97.     ASTBase *left() { return _left; }
  98.     ASTBase *up() { return _up; }
  99. };
  100.  
  101. class AST;    // announce that this class will be coming along shortly
  102. #endif
  103.